package com.zking.ssm.controller;

import com.zking.ssm.model.HotelRoom;
import com.zking.ssm.service.IHotelRoomService;
import com.zking.ssm.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController  //返回json格式的数据
@RequestMapping("/Room") //窄化路径
public class HotelRoomController {

    @Autowired
    private IHotelRoomService iHotelRoomService;


    @RequestMapping("/list")
    public Map<String,Object> list(HotelRoom hotelRoom){
        System.out.println(hotelRoom);
        PageBean pageBean = new PageBean();
        List<HotelRoom> list = iHotelRoomService.SelectAll(hotelRoom, pageBean);
        Map<String,Object> map = new HashMap<>();
        if(list.size() > 0){
            map.put("code",0);
            map.put("message","查询房型成功！");
            map.put("request",list);
        }else{
            map.put("code",-1);
            map.put("message","查询房型失败！");
        }
        return map;
    }

    @RequestMapping("/add")
    public Map<String,Object> add(HotelRoom hotelRoom){
        System.out.println(hotelRoom);
        int n = iHotelRoomService.insert(hotelRoom);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","增加房型成功！");
        }else{
            map.put("code",-1);
            map.put("message","增加房型失败！");
        }
        return map;
    }

    @RequestMapping("/del")
    public Map<String,Object> del(HotelRoom hotelRoom){
        int n = iHotelRoomService.deleteByPrimaryKey(hotelRoom.getId());
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","删除房型成功！");
        }else{
            map.put("code",-1);
            map.put("message","删除房型失败！");
        }
        return map;
    }

    @RequestMapping("/update")
    public Map<String,Object> update(HotelRoom hotelRoom){
        int n = iHotelRoomService.updateByPrimaryKeySelective(hotelRoom);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","修改房型成功！");
        }else{
            map.put("code",-1);
            map.put("message","修改房型失败！");
        }
        return map;
    }

    @RequestMapping("/get")
    public Map<String,Object> get(HotelRoom hotelRoom){
        HotelRoom user = iHotelRoomService.selectByPrimaryKey(hotelRoom.getId());
        System.out.println(user);
        Map<String,Object> map = new HashMap<>();
        if(user != null){

            map.put("code",0);
            map.put("message","查询房型成功！");
            map.put("request",user);
        }else{
            map.put("code",-1);
            map.put("message","查询房型失败！");
        }
        return map;
    }




}
